<!DOCTYPE html>



  


<html class="theme-next pisces use-motion" lang="">
<head>
  <meta charset="UTF-8"/>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>
<meta name="theme-color" content="#222">









<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />
















  
  
  <link href="/blog/lib/fancybox/source/jquery.fancybox.css?v=2.1.5" rel="stylesheet" type="text/css" />







<link href="/blog/lib/font-awesome/css/font-awesome.min.css?v=4.6.2" rel="stylesheet" type="text/css" />

<link href="/blog/css/main.css?v=5.1.4" rel="stylesheet" type="text/css" />


  <link rel="apple-touch-icon" sizes="180x180" href="/blog/images/apple-touch-icon-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="32x32" href="/blog/images/favicon-32x32-next.png?v=5.1.4">


  <link rel="icon" type="image/png" sizes="16x16" href="/blog/images/favicon-16x16-next.png?v=5.1.4">


  <link rel="mask-icon" href="/blog/images/logo.svg?v=5.1.4" color="#222">





  <meta name="keywords" content="Hexo, NexT" />










<meta name="description" content="####1. Dubbo官网Dubbo下载地址 ######1). 发展历史随着互联网的不断发展，网站的应用规模越来越大，常规的垂直架构已经无法应对，尤其是类似电商的项目，所以分布式架构和流动计算架构已经势在必行。Dubbo就是资源调度和服务治理中心的管理工具。① 单一应用架构(ORM)    当网站流量很小时，只需一个应用，将所有功能如下单支付等都部署在一起，以减少部署节点和成本。 缺点：单一的">
<meta name="keywords" content="Android、iOS、Web、React Native">
<meta property="og:type" content="article">
<meta property="og:title" content="分布式--Dubbo-分布式服务">
<meta property="og:url" content="http://yoursite.com/blog/2018/08/06/Distributed/分布式--Dubbo-分布式服务/index.html">
<meta property="og:site_name" content="凌浩雨_博客">
<meta property="og:description" content="####1. Dubbo官网Dubbo下载地址 ######1). 发展历史随着互联网的不断发展，网站的应用规模越来越大，常规的垂直架构已经无法应对，尤其是类似电商的项目，所以分布式架构和流动计算架构已经势在必行。Dubbo就是资源调度和服务治理中心的管理工具。① 单一应用架构(ORM)    当网站流量很小时，只需一个应用，将所有功能如下单支付等都部署在一起，以减少部署节点和成本。 缺点：单一的">
<meta property="og:locale" content="default">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-d44027339d050480.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-8d18739b59fef16e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-438b717af239f490.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-f16dd85202b556d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-8f538ee42acafd1e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-26d8f6c663dd62a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-14f6225eef8188fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-9a8e595a06091216.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-7e5e4d50e4c696d3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-a334ae8435fa4242.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-3c5941a3e687b70f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-8b193422cacdfa8c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-e8e0ad4b4cd46d8d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-7abec29c56c7a04c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-ea4a90d749f6491d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-8c9347070b4d2fc8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-a085be1248ebe6d5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-191da42e977b4bbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-ccfc30ebe65c82a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-a38258a211482d5b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-f3077c94cf35fa2d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-d11a87585547b95f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-b4c4655162cacfd4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-1f0038498bc1596c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-733526a24d178d0e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:image" content="https://upload-images.jianshu.io/upload_images/3110861-fb3b761872b8bb44.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">
<meta property="og:updated_time" content="2018-08-06T11:06:24.257Z">
<meta name="twitter:card" content="summary">
<meta name="twitter:title" content="分布式--Dubbo-分布式服务">
<meta name="twitter:description" content="####1. Dubbo官网Dubbo下载地址 ######1). 发展历史随着互联网的不断发展，网站的应用规模越来越大，常规的垂直架构已经无法应对，尤其是类似电商的项目，所以分布式架构和流动计算架构已经势在必行。Dubbo就是资源调度和服务治理中心的管理工具。① 单一应用架构(ORM)    当网站流量很小时，只需一个应用，将所有功能如下单支付等都部署在一起，以减少部署节点和成本。 缺点：单一的">
<meta name="twitter:image" content="https://upload-images.jianshu.io/upload_images/3110861-d44027339d050480.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240">



<script type="text/javascript" id="hexo.configurations">
  var NexT = window.NexT || {};
  var CONFIG = {
    root: '/blog/',
    scheme: 'Pisces',
    version: '5.1.4',
    sidebar: {"position":"left","display":"post","offset":12,"b2t":false,"scrollpercent":false,"onmobile":false},
    fancybox: true,
    tabs: true,
    motion: {"enable":true,"async":false,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},
    duoshuo: {
      userId: '0',
      author: 'Author'
    },
    algolia: {
      applicationID: '',
      apiKey: '',
      indexName: '',
      hits: {"per_page":10},
      labels: {"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}
    }
  };
</script>



  <link rel="canonical" href="http://yoursite.com/blog/2018/08/06/Distributed/分布式--Dubbo-分布式服务/"/>





  <title>分布式--Dubbo-分布式服务 | 凌浩雨_博客</title>
  








</head>

<body itemscope itemtype="http://schema.org/WebPage" lang="default">

  
  
    
  

  <div class="container sidebar-position-left page-post-detail">
    <div class="headband"></div>

    <header id="header" class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-wrapper">
  <div class="site-meta ">
    

    <div class="custom-logo-site-title">
      <a href="/blog/"  class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">凌浩雨_博客</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
      
        <p class="site-subtitle"></p>
      
  </div>

  <div class="site-nav-toggle">
    <button>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
      <span class="btn-bar"></span>
    </button>
  </div>
</div>

<nav class="site-nav">
  

  
    <ul id="menu" class="menu">
      
        
        <li class="menu-item menu-item-home">
          <a href="/blog/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-home"></i> <br />
            
            Home
          </a>
        </li>
      
        
        <li class="menu-item menu-item-archives">
          <a href="/blog/archives/" rel="section">
            
              <i class="menu-item-icon fa fa-fw fa-archive"></i> <br />
            
            Archives
          </a>
        </li>
      

      
    </ul>
  

  
</nav>



 </div>
    </header>

    <main id="main" class="main">
      <div class="main-inner">
        <div class="content-wrap">
          <div id="content" class="content">
            

  <div id="posts" class="posts-expand">
    

  

  
  
  

  <article class="post post-type-normal" itemscope itemtype="http://schema.org/Article">
  
  
  
  <div class="post-block">
    <link itemprop="mainEntityOfPage" href="http://yoursite.com/blog/blog/2018/08/06/Distributed/分布式--Dubbo-分布式服务/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="name" content="凌浩雨">
      <meta itemprop="description" content="">
      <meta itemprop="image" content="/blog/images/avatar.jpeg">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="凌浩雨_博客">
    </span>

    
      <header class="post-header">

        
        
          <h1 class="post-title" itemprop="name headline">分布式--Dubbo-分布式服务</h1>
        

        <div class="post-meta">
          <span class="post-time">
            
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              
                <span class="post-meta-item-text">Posted on</span>
              
              <time title="Post created" itemprop="dateCreated datePublished" datetime="2018-08-06T18:01:38+08:00">
                2018-08-06
              </time>
            

            

            
          </span>

          

          
            
          

          
          

          

          

          

        </div>
      </header>
    

    
    
    
    <div class="post-body" itemprop="articleBody">

      
      

      
        <p>####1. <a href="http://dubbo.apache.org/" target="_blank" rel="noopener">Dubbo官网</a><br><a href="http://mvnrepository.com/artifact/com.alibaba/dubbo" target="_blank" rel="noopener">Dubbo下载地址</a></p>
<p>######1). 发展历史<br>随着互联网的不断发展，网站的应用规模越来越大，常规的垂直架构已经无法应对，尤其是类似电商的项目，所以分布式架构和流动计算架构已经势在必行。Dubbo就是资源调度和服务治理中心的管理工具。<br>① 单一应用架构(ORM)<br>    当网站流量很小时，只需一个应用，将所有功能如下单支付等都部署在一起，以减少部署节点和成本。 缺点：单一的系统架构，使得在开发过程中，占用的资源越来越多，而且随着流量的增加越来越难以维护<br><img src="https://upload-images.jianshu.io/upload_images/3110861-d44027339d050480.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图1.png"><br><a id="more"></a></p>
<p>② 垂直应用架构(MVC)<br>    垂直应用架构解决了单一应用架构所面临的扩容问题，流量能够分散到各个子系统当中，且系统的体积可控，一定程度上降低了开发人员之间协同以及维护的成本，提升了开发效率。 缺点：但是在垂直架构中相同逻辑代码需要不断的复制，不能复用。<br><img src="https://upload-images.jianshu.io/upload_images/3110861-8d18739b59fef16e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图2.png"></p>
<p>③ 分布式服务架构(RPC)<br>    当垂直应用越来越多，有很多相同的业务逻辑，这样应用直接的交互不可避免，此时将核心业务抽取出来，作为独立的服务，逐 渐形成稳定的服务中心，以应对快速变化的外部市场环境。<br><img src="https://upload-images.jianshu.io/upload_images/3110861-438b717af239f490.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图3.png"></p>
<p>④ 流动计算架构(SOA)<br>    当服务越来越多，容量的评估，小服务资源浪费等问题逐渐暴露，此时需要一个服务治理工具来管理集群容量，提高利用率。<br>  <img src="https://upload-images.jianshu.io/upload_images/3110861-f16dd85202b556d2.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图4.png"></p>
<p>######2). 为什么使用dubbo？<br>1.webservice：效率不高基于soap协议，项目中不建议使用，但它的优点在于跨语言通信，适用于不同公司相互调用接口。<br>2.使用restful形式服务：http+json。很多项目中的应用，如果服务太多，系统之间调用关系混乱，需要治疗服务。<br>3.使用dubbo。使用rpc协议进行远程调用，之间使用socket通信，传输效率高，并且可以统计出系统之间的调用关系、调用次数。<br>说白了dubbo就是一个服务治理工具，是一个服务的中间件，由于dubbo是通过java编写的，dubbo最大的缺点就出现了，它只适用于java系统间的通信。</p>
<p>######3). Dubbo架构<br>角色说明：</p>
<ul>
<li>Provider：暴露服务的服务提供方</li>
<li>Container：服务运行容器</li>
<li>Consumer：调用服务的消费方</li>
<li>Registry：注册服务与发现服务中心</li>
<li>Monitor：统计服务调用的监控中心（可有可无）<br><img src="https://upload-images.jianshu.io/upload_images/3110861-8f538ee42acafd1e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图5.png"></li>
</ul>
<p>调用关系说明：<br>0：服务运行容器启动，加载服务提供者<br>1：在启动时告诉注册中心服务方有什么服务<br>2：消费者调用服务时，先到注册中心订阅所需要服务<br>3：注册中心返回结果即该服务的地址<br>4：消费者通过地址调用服务（此时注册中心没用了）<br>5：服务消费者和提供者，在内存中累计调用次数和调用时间，定时每分钟发送一次到监控中心</p>
<p>######4). RPC(Remote Procedure Call Protocol)<br>远程过程调用： 两台服务器A、B，分别部署不同的应用a,b。当A服务器想要调用B服务器上应用b提供的函数或方法的时候，由于不在一个内存空间，不能直接调用，需要通过网络来表达调用的语义传达调用的数据。<br><img src="https://upload-images.jianshu.io/upload_images/3110861-26d8f6c663dd62a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图6.png"></p>
<blockquote>
<p>RPC是一种通过网络从远程计算机程序上请求服务，而不需要了解底层网络技术的协议。RPC协议假定某些传输协议的存在，如TCP或UDP，为通信程序之间携带信息数据。在OSI网络通信模型中，RPC跨越了传输层和应用层。RPC使得开发包括网络分布式多程序在内的应用程序更加容易。 RPC采用客户机/服务器模式。请求程序就是一个客户机，而服务提供程序就是一个服务器。首先，客户机调用进程发送一个有进程参数的调用信息到服务进程，然后等待应答信息。在服务器端，进程保持睡眠状态直到调用信息到达为止。当一个调用信息到达，服务器获得进程参数，计算结果，发送答复信息，然后等待下一个调用信息，最后，客户端调用进程接收答复信息，获得进程结果，然后调用执行继续进行。</p>
</blockquote>
<p>######5). Dubbo的注册中心</p>
<ul>
<li>Multicast注册中心</li>
<li>Zookeeper注册中心</li>
<li>Redis注册中心</li>
<li>Simple注册中心</li>
</ul>
<p>######6). Dubbo优缺点</p>
<ul>
<li>优点：</li>
</ul>
<ol>
<li>透明化的远程方法调用：像调用本地方法一样调用远程方法；只需简单配置，没有任何API侵入。</li>
<li>软负载均衡及容错机制：可在内网替代nginx lvs等硬件负载均衡器。</li>
<li>服务注册中心自动注册 &amp; 配置管理：不需要写死服务提供者地址，注册中心基于接口名自动查询提供者ip。使用类似zookeeper等分布式协调服务作为服务注册中心，可以将绝大部分项目配置移入zookeeper集群。</li>
<li>服务接口监控与治理 ：Dubbo-admin与Dubbo-monitor提供了完善的服务接口管理与监控功能，针对不同应用的不同接口，可以进行 多版本，多协议，多注册中心管理。</li>
</ol>
<ul>
<li>缺点：只支持JAVA语言</li>
</ul>
<p>####2. Spring+Dubbo+ZooKeeper实例</p>
<p>######1). 准备jar包(共16个)</p>
<ul>
<li><strong><a href="http://repo.springsource.org/libs-release-local/org/springframework/spring/" target="_blank" rel="noopener">Spring</a>: </strong> commons-logging-1.2.jar、spring-aop-5.0.5.RELEASE.jar、spring-beans-5.0.5.RELEASE.jar、spring-context-5.0.5.RELEASE.jar、spring-core-5.0.5.RELEASE.jar、spring-expression-5.0.5.RELEASE.jar</li>
<li><strong><a href="http://mvnrepository.com/artifact/com.alibaba/dubbo" target="_blank" rel="noopener">Dubbo</a>: </strong> dubbo-2.6.1.jar</li>
<li><strong><a href="http://49.119.164.213:6510/mirror.bit.edu.cn/apache/zookeeper/zookeeper-3.4.10/zookeeper-3.4.10.tar.gz" target="_blank" rel="noopener">ZooKeeper</a>: </strong> log4j-1.2.16.jar、slf4j-api-1.6.1.jar、slf4j-log4j12-1.6.1.jar、netty-3.10.5.Final.jar、zookeeper-3.4.10.jar</li>
<li><strong>Other: </strong><a href="http://mvnrepository.com/artifact/org.apache.curator/curator-client" target="_blank" rel="noopener">curator-client-4.0.1.jar</a>、<a href="http://mvnrepository.com/artifact/org.apache.curator/curator-framework" target="_blank" rel="noopener">curator-framework-4.0.1.jar</a>、<a href="http://jboss-javassist.github.io/javassist/" target="_blank" rel="noopener">javassist-3.22.0-GA.jar</a>、<a href="https://www.seleniumhq.org/download/" target="_blank" rel="noopener">selenium-server-standalone-3.11.0.jar</a><br><img src="https://upload-images.jianshu.io/upload_images/3110861-14f6225eef8188fa.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图7.png"></li>
</ul>
<p>######2). 创建Dubbo-api Java项目<br>I. 引入jar包<br>右键项目 -&gt; Build Path -&gt; Configure Build Path… -&gt; Libraries -&gt; Add External JARs… 找到自己刚刚存放jar包的文件夹，我的是在<code>E:\eclipse\libs\</code>文件夹中，全选(Ctrl+A)jar包，点击打开—&gt; OK. 导包成功.<br><img src="https://upload-images.jianshu.io/upload_images/3110861-9a8e595a06091216.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图8.png"></p>
<p>II. 将解压ZooKeeper后的文件夹中/conf/文件夹下的log4j.properties拷贝到工程的src目录下<br><img src="https://upload-images.jianshu.io/upload_images/3110861-7e5e4d50e4c696d3.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图9.png"></p>
<p>III. 在src下创建ItemService接口<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">public interface ItemService &#123;</span><br><span class="line">	List&lt;String&gt; getList(Long id);</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>IV. Dubbo-api 工程目录结构<br><img src="https://upload-images.jianshu.io/upload_images/3110861-a334ae8435fa4242.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图10.png"></p>
<p>######3). 创建Dubbo-provider Java工程<br>I. 导包–方法同上<br>II. 依赖上一步完成的Dubbo-api Java工程<br>工程上右键 -&gt; Build Path -&gt; Configure Build Path… -&gt; Project -&gt; Add… -&gt;选择Dubbo-api 点击OK -&gt; OK<br>III. 创建ItemService的实现类ItemServiceImpl<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br></pre></td><td class="code"><pre><span class="line">public class ItemServiceImpl implements ItemService&#123;</span><br><span class="line"></span><br><span class="line">	@Override</span><br><span class="line">	public List&lt;String&gt; getList(Long id) &#123;</span><br><span class="line">		List&lt;String&gt; list = new ArrayList&lt;&gt;();</span><br><span class="line">		for (int i = 0; i &lt; 20; i++) &#123;</span><br><span class="line">			list.add(&quot;item&quot; + i);</span><br><span class="line">		&#125;</span><br><span class="line">		return list;</span><br><span class="line">	&#125;</span><br><span class="line"></span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>IV. 在src目录下创建provider.xml文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;beans </span><br><span class="line">	xmlns=&quot;http://www.springframework.org/schema/beans&quot;</span><br><span class="line">	xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><br><span class="line">	xmlns:dubbo=&quot;http://code.alibabatech.com/schema/dubbo&quot;</span><br><span class="line">	xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans</span><br><span class="line">       http://www.springframework.org/schema/beans/spring-beans.xsd</span><br><span class="line">       http://code.alibabatech.com/schema/dubbo </span><br><span class="line">       http://code.alibabatech.com/schema/dubbo/dubbo.xsd&quot;&gt;</span><br><span class="line">	</span><br><span class="line">	&lt;!-- 定义了提供方应用信息，用于计算依赖关系，在 dubbo-admin 或 dubbo-monitor 会显示这个名字，方便辨识 --&gt;</span><br><span class="line">	&lt;dubbo:application name=&quot;Dubbo-provider&quot; owner=&quot;programmer&quot; organization=&quot;mazaiting&quot;/&gt;</span><br><span class="line">	&lt;!-- 使用ZooKeeper 注册中心暴露服务，注意要先开启ZooKeeper --&gt;</span><br><span class="line">	&lt;dubbo:registry address=&quot;zookeeper://127.0.0.1:2181&quot;/&gt;</span><br><span class="line">	&lt;!-- 使用Dubbo协议在20880端口暴露服务 --&gt;</span><br><span class="line">	&lt;dubbo:protocol name=&quot;dubbo&quot; port=&quot;20880&quot;/&gt;</span><br><span class="line">	&lt;!-- 使用dubbo 协议实现定义好的服务接口 --&gt;</span><br><span class="line">	&lt;dubbo:service protocol=&quot;dubbo&quot; ref=&quot;itemService&quot; interface=&quot;com.mazaiting.service.ItemService&quot;/&gt;</span><br><span class="line">	&lt;!-- 具体实现该接口的bean --&gt;</span><br><span class="line">	&lt;bean id=&quot;itemService&quot; class=&quot;com.mazaiting.service.impl.ItemServiceImpl&quot;/&gt;</span><br><span class="line">	</span><br><span class="line">&lt;/beans&gt;</span><br></pre></td></tr></table></figure></p>
<p><strong>如果遇到无法快捷提示dubbo标签的情况， 请<a href="https://www.jianshu.com/p/724881ac51ea" target="_blank" rel="noopener">参考此文–Dubbo 无法加载dubbo.xsd</a></strong><br>V. 创建Provider类，此类中启动此工程<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">public class Provider &#123;</span><br><span class="line">	public static void main(String[] args) throws IOException &#123;</span><br><span class="line">		ClassPathXmlApplicationContext context = </span><br><span class="line">				new ClassPathXmlApplicationContext(&quot;provider.xml&quot;);</span><br><span class="line">		System.out.println(context.getDisplayName() + &quot; : here&quot;);</span><br><span class="line">		context.start();</span><br><span class="line">		System.out.println(&quot;服务已经启动...&quot;);</span><br><span class="line">		System.in.read();</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>VI. Dubbo-provider 工程目录结构<br><img src="https://upload-images.jianshu.io/upload_images/3110861-3c5941a3e687b70f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图11.png"></p>
<p>######4). 创建Dubbo-consumer Java工程<br>I. 导包 – 方法同上<br>II. 在src下创建consumer.xml配置文件<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br></pre></td><td class="code"><pre><span class="line">&lt;?xml version=&quot;1.0&quot; encoding=&quot;UTF-8&quot;?&gt;</span><br><span class="line">&lt;beans xmlns=&quot;http://www.springframework.org/schema/beans&quot;</span><br><span class="line">       xmlns:xsi=&quot;http://www.w3.org/2001/XMLSchema-instance&quot;</span><br><span class="line">       xmlns:dubbo=&quot;http://code.alibabatech.com/schema/dubbo&quot;</span><br><span class="line">       xsi:schemaLocation=&quot;http://www.springframework.org/schema/beans </span><br><span class="line">       http://www.springframework.org/schema/beans/spring-beans.xsd</span><br><span class="line">       http://code.alibabatech.com/schema/dubbo </span><br><span class="line">       http://code.alibabatech.com/schema/dubbo/dubbo.xsd&quot;&gt;</span><br><span class="line">		&lt;!-- 定义了提供方应用信息，用于计算依赖关系，在 dubbo-admin 或 dubbo-monitor 会显示这个名字，方便辨识 --&gt;</span><br><span class="line">		&lt;dubbo:application name=&quot;Dubbo-consumer&quot; owner=&quot;programmer&quot; organization=&quot;mazaiting&quot;/&gt;</span><br><span class="line">		&lt;!-- 向ZooKeeper 订阅provider的地址， 由ZooKeeper定时推送 --&gt;</span><br><span class="line">		&lt;dubbo:registry address=&quot;zookeeper://127.0.0.1:2181&quot;/&gt;</span><br><span class="line">		&lt;!-- 使用协议调用定义好的接口 --&gt;</span><br><span class="line">		&lt;dubbo:reference id=&quot;itemService&quot; interface=&quot;com.mazaiting.service.ItemService&quot;/&gt;</span><br><span class="line">&lt;/beans&gt;</span><br></pre></td></tr></table></figure></p>
<p>III. 创建Consumer类来启动当前工程<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">public class Consumer &#123;</span><br><span class="line">	public static void main(String[] args) &#123;</span><br><span class="line">		ClassPathXmlApplicationContext context = </span><br><span class="line">				new ClassPathXmlApplicationContext(&quot;consumer.xml&quot;);</span><br><span class="line">		context.start();</span><br><span class="line">		System.out.println(&quot;consumer start&quot;);</span><br><span class="line">		ItemService demoService = context.getBean(ItemService.class);</span><br><span class="line">		System.out.println(&quot;consumer&quot;);</span><br><span class="line">		List&lt;String&gt; list = demoService.getList(1L);</span><br><span class="line">		for (String string : list) &#123;</span><br><span class="line">			System.out.println(string);	</span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&#125;</span><br></pre></td></tr></table></figure></p>
<p>IV. Dubbo-consumer 工程目录结构<br><img src="https://upload-images.jianshu.io/upload_images/3110861-8b193422cacdfa8c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图12.png"></p>
<p>######5). 测试<br>I.  开启ZooKeeper – <a href="https://www.jianshu.com/p/daff5a14add2" target="_blank" rel="noopener">ZooKeeper安装及使用</a><br>II. 执行Dubbo-provider工程中的Provider类<br><img src="https://upload-images.jianshu.io/upload_images/3110861-e8e0ad4b4cd46d8d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图13.png"><br>III. 再启动Dubbo-consumer工程中的Consumer类<br><img src="https://upload-images.jianshu.io/upload_images/3110861-7abec29c56c7a04c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图15.png"></p>
<p>####3. Dubbo 控制台安装</p>
<p>######1). <a href="https://github.com/apache/incubator-dubbo-ops" target="_blank" rel="noopener">Dubbo-admin下载</a></p>
<p>######2). 编译项目<br>编译项目需要使用到Maven命令， <a href="https://www.jianshu.com/p/6453f8e27346" target="_blank" rel="noopener">Linux 安装Maven</a> 和<a href="https://www.jianshu.com/p/bb694e75ae6b" target="_blank" rel="noopener">Windows 安装Maven</a><br>下载之后解压，并进入incubator-dubbo-ops-master文件夹，在命令提示符窗口中输入<br><figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br></pre></td><td class="code"><pre><span class="line">mvn clean package</span><br></pre></td></tr></table></figure></p>
<p>编译成功如下图:<br><img src="https://upload-images.jianshu.io/upload_images/3110861-ea4a90d749f6491d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图16.png"></p>
<p>######3). 安装<a href="https://tomcat.apache.org/download-80.cgi" target="_blank" rel="noopener">Tomcat容器</a></p>
<p><img src="https://upload-images.jianshu.io/upload_images/3110861-8c9347070b4d2fc8.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图17.png"><br><strong>这里我下载的是zip包</strong>，下载后并解压<br><img src="https://upload-images.jianshu.io/upload_images/3110861-a085be1248ebe6d5.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图18.png"></p>
<p>######4). 复制文件<br>将incubator-dubbo-ops-master\dubbo-admin\target\下的dubbo-admin-2.0.0.war复制到apache-tomcat-8.5.31\webapps\目录下<br><img src="https://upload-images.jianshu.io/upload_images/3110861-191da42e977b4bbe.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图19.png"></p>
<p>######5). 解压<br>将dubbo-admin-2.0.0.war解压<br><img src="https://upload-images.jianshu.io/upload_images/3110861-ccfc30ebe65c82a0.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图20.png"><br><strong>在WEB-INF/dubbo.properties文件中可以配置ZooKeeper地址，管理员密码</strong></p>
<p>####4. 使用Dubbo-admin</p>
<p>######1).  开启ZooKeeper<br><img src="https://upload-images.jianshu.io/upload_images/3110861-a38258a211482d5b.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图21.png"></p>
<p>######2). 开启Tomcat</p>
<ul>
<li>双击startup.bat批处理开发<br><img src="https://upload-images.jianshu.io/upload_images/3110861-f3077c94cf35fa2d.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图22.png"></li>
<li>浏览器打开<code>http://localhost:8080/dubbo-admin-2.0.0</code>页面<br><img src="https://upload-images.jianshu.io/upload_images/3110861-d11a87585547b95f.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图23.png"><br><strong>用户名和密码默认的均为root</strong>，此时登录后数据为空。<br><img src="https://upload-images.jianshu.io/upload_images/3110861-b4c4655162cacfd4.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图24.png"></li>
</ul>
<p>######3). 在Eclipse中运行Dubbo-provider项目<br>程序启动后刷新<code>http://localhost:8080/dubbo-admin-2.0.0/governance/providers</code><br><img src="https://upload-images.jianshu.io/upload_images/3110861-1f0038498bc1596c.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图25.png"><br>此时提供者已有数据，再进入消费者页面<br><img src="https://upload-images.jianshu.io/upload_images/3110861-733526a24d178d0e.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图26.png"></p>
<p>######4). 在Eclipse中运行Dubbo-consumer项目<br>程序启动后，Eclipse控制台打印出数据，刷新<code>http://localhost:8080/dubbo-admin-2.0.0/governance/consumers</code>页面<br><img src="https://upload-images.jianshu.io/upload_images/3110861-fb3b761872b8bb44.png?imageMogr2/auto-orient/strip%7CimageView2/2/w/1240" alt="图27.png"><br>此时消费者页面也有数据了。</p>
<p>####<a href="https://gitee.com/mazaiting/distributed" target="_blank" rel="noopener">代码下载</a></p>

      
    </div>
    
    
    

    

    

    

    <footer class="post-footer">
      

      
      
      

      
        <div class="post-nav">
          <div class="post-nav-next post-nav-item">
            
              <a href="/blog/2018/08/06/Distributed/分布式--ActiveMQ-消息中间件(二)/" rel="next" title="分布式--ActiveMQ-消息中间件(二)">
                <i class="fa fa-chevron-left"></i> 分布式--ActiveMQ-消息中间件(二)
              </a>
            
          </div>

          <span class="post-nav-divider"></span>

          <div class="post-nav-prev post-nav-item">
            
              <a href="/blog/2018/08/06/Distributed/分布式--Ehcache缓存/" rel="prev" title="分布式--Ehcache缓存">
                分布式--Ehcache缓存 <i class="fa fa-chevron-right"></i>
              </a>
            
          </div>
        </div>
      

      
      
    </footer>
  </div>
  
  
  
  </article>



    <div class="post-spread">
      
    </div>
  </div>


          </div>
          


          

  



        </div>
        
          
  
  <div class="sidebar-toggle">
    <div class="sidebar-toggle-line-wrap">
      <span class="sidebar-toggle-line sidebar-toggle-line-first"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-middle"></span>
      <span class="sidebar-toggle-line sidebar-toggle-line-last"></span>
    </div>
  </div>

  <aside id="sidebar" class="sidebar">
    
    <div class="sidebar-inner">

      

      

      <section class="site-overview-wrap sidebar-panel sidebar-panel-active">
        <div class="site-overview">
          <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
            
              <img class="site-author-image" itemprop="image"
                src="/blog/images/avatar.jpeg"
                alt="凌浩雨" />
            
              <p class="site-author-name" itemprop="name">凌浩雨</p>
              <p class="site-description motion-element" itemprop="description">专业从事于移动端开发，Android与iOS均有涉及，主做Android开发与React Native开发</p>
          </div>

          <nav class="site-state motion-element">

            
              <div class="site-state-item site-state-posts">
              
                <a href="/blog/archives/">
              
                  <span class="site-state-item-count">393</span>
                  <span class="site-state-item-name">posts</span>
                </a>
              </div>
            

            

            

          </nav>

          

          

          
          

          
          

          

        </div>
      </section>

      

      

    </div>
  </aside>


        
      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="footer-inner">
        <div class="copyright">&copy; <span itemprop="copyrightYear">2018</span>
  <span class="with-love">
    <i class="fa fa-user"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">凌浩雨</span>

  
</div>


  <div class="powered-by">Powered by <a class="theme-link" target="_blank" href="https://hexo.io">Hexo</a></div>



  <span class="post-meta-divider">|</span>



  <div class="theme-info">Theme &mdash; <a class="theme-link" target="_blank" href="https://github.com/iissnan/hexo-theme-next">NexT.Pisces</a> v5.1.4</div>




        







        
      </div>
    </footer>

    
      <div class="back-to-top">
        <i class="fa fa-arrow-up"></i>
        
      </div>
    

    

  </div>

  

<script type="text/javascript">
  if (Object.prototype.toString.call(window.Promise) !== '[object Function]') {
    window.Promise = null;
  }
</script>









  












  
  
    <script type="text/javascript" src="/blog/lib/jquery/index.js?v=2.1.3"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fastclick/lib/fastclick.min.js?v=1.0.6"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/jquery_lazyload/jquery.lazyload.js?v=1.9.7"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/velocity/velocity.ui.min.js?v=1.2.1"></script>
  

  
  
    <script type="text/javascript" src="/blog/lib/fancybox/source/jquery.fancybox.pack.js?v=2.1.5"></script>
  


  


  <script type="text/javascript" src="/blog/js/src/utils.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/motion.js?v=5.1.4"></script>



  
  


  <script type="text/javascript" src="/blog/js/src/affix.js?v=5.1.4"></script>

  <script type="text/javascript" src="/blog/js/src/schemes/pisces.js?v=5.1.4"></script>



  
  <script type="text/javascript" src="/blog/js/src/scrollspy.js?v=5.1.4"></script>
<script type="text/javascript" src="/blog/js/src/post-details.js?v=5.1.4"></script>



  


  <script type="text/javascript" src="/blog/js/src/bootstrap.js?v=5.1.4"></script>



  


  




	





  





  












  





  

  

  

  
  

  

  

  

</body>
</html>
